﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Othello_Game
{
    /// <summary>
    /// A normalize attribute implementing IAttributeNormalizedValues interface.
    /// Returns a score indicating the difference between the number of player's pieces.
    /// The value is normalized by the total ammount of pieces conquered so far.
    /// Also a preference for a larger difference on later moves is taken.
    /// </summary>
    public class PlayersPiecesDifferenceAttribute : IAttributeNormalizedValues
    {
        /// <summary>
        /// Attribute value for the diffrenece in player's pieces
        /// </summary>
        /// <param name="actionList">A move to play</param>
        /// <returns>A value effected by the difference between the player's pieces
        /// and consideration of the turns played so far. </returns>
        public double GetAttributeValues(ActionList actionList)
        {
            double diff = 0.0;

            Score boardScore = actionList.BoardState.GetBoardScore();

            switch (actionList.BoardState.CurrentPlayer)
	        {
                case players.PLAYER1:
                    diff = (double) boardScore.BlackPlayer - boardScore.WhitePlayer;
                    break;
                case players.PLAYER2:
                    diff = (double) boardScore.WhitePlayer - boardScore.BlackPlayer;
                    break;
                default:
                    break;
	        }

            // If less then 36 pieces on board, we dont want a large difference
            if (boardScore.BlackPlayer + boardScore.WhitePlayer < 36) diff *= -1.0;

            return diff/(double)(boardScore.WhitePlayer + boardScore.BlackPlayer);
        }
    }
}
